package praktikumid.p02_t;

/**
 * Variable examples.
 * @author ago.luberg
 *
 */
public class Variables {
	
	// magic number problem
	
	/**
	 * option "play".
	 */
	static final int PLAY = 1;
	/**
	 * option "hiscores".
	 */
	static final int HISCORES = 2;
	/**
	 * option "options".
	 */
	static final int OPTIONS = 3;
	/**
	 * option "exit".
	 */
	static final int EXIT = 4;
	
	/**
	 * important number.
	 */
	//static int n = 2;
	
	/**
	 * Another important number
	 */
	static int m = 3;
	/**
	 * @param args Arguments from command line
	 */
	public static void main(String[] args) {
		// 
		int n = 4;
		System.out.println(n);
		//System.out.println(Variables.n);
		System.out.println(m);
		
		n = n + 3; // n = 7
		// 7 / 2 = 3.5 => 3
		System.out.println(n);
		
		
		// double 1.123123123123
		// float  1.123128
		//float f = (float)1.1;
		float f = 1.5f;
		f = 7;
		System.out.println(f);
		System.out.println(f / 3);
		
		// if conditions
		// C-s: if (0) => if (false)
		// if (15) => if (true)
		// if (n) ...
		if (true) {
			// condition is TRUE
		} else {
			// if condition is FALSE
		}
		n = 1;
		if (n > 3) {
			System.out.println("n on suurem kui 3");
		} else {
			System.out.println("n on väiksem-võrdne kui 3");			
		}
		// switch
		/*
		 * 1. play
		 * 2. hiscores
		 * 3. options
		 * 4. exit
		 */
		
		// if:
		if (n == PLAY) {
			System.out.println("Let's play!");
			n = 2;
		} else if (n == HISCORES) {
			System.out.println("best score!");
		} else if (n == OPTIONS) {
			System.out.println("no options!");
		} else {
			System.out.println("bye!");
		}
		n = 2;
		switch (n) {
		case PLAY:
		case 6:
		case 8:
			System.out.println("Let's play!");
			break;
		case HISCORES:
			System.out.println("best scores!");
			break;
		case OPTIONS:
			System.out.println("options!");
			break;
		default:
			System.out.println("bye!");
			break;
			
		}
		
		
		
		// loops

		// 1) while (true)
		int i = 10;
		while (true) {
			// endless loop
			System.out.println(i + " Please" + " stop!");
			i = i - 1;
			if (i <= 0) {
				break;
			}
			//System.out.println("are we there yet!");
		}
		// 2) while (condition)
		i = 10;
		while (i > 0) {
			System.out.println(i + " Please" + " stop!");
			i = i - 1;
		}
		// 3) for
		// for (algväärtustamine; tingimus; iteratsioon)
		// i-- <==> i = i - 1
		for (i = 10; i > 0; i--) {
			System.out.println(i + " Please" + " stop!");
		}
		
		i = 10;
		for ( ; i > 0; ) {
			// while (i > 0)
			System.out.println(i + " Please" + " stop!");
			i = i - 1;
		}
		

		// let's define j as we will use it in the inner loop
		int j;
		for (i = 1; i <= 10; i = i + 1) {
			// i = [1..10]
			System.out.printf("%1$3s", i);
			for (j = 1; j <= 10; j++) {
				// j = [1..10]
				System.out.printf("%1$3s", i * j);
			}
			System.out.println();
		}
		
		String s = "exit";
		s += "";
		System.out.println(s == "exit"); // false, although both are "exit"
		// string comparison
		if (s.equalsIgnoreCase("exit")) { // true, compares content
			System.out.println("bye");
		} else {
			System.out.println("hi");
		}
		
		if ("exit".equalsIgnoreCase(s)) {
			
		}
		
		
		
		
		
		
		
	}
}